﻿using Prism.Commands;
using Prism.Mvvm;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WPFStudy.PrismStudy.Views;

namespace WPFStudy.PrismStudy.ViewModels
{
    public class DialogViewModel:BindableBase
    {

        private readonly IDialogService _dialogService;

        public DialogViewModel(IDialogService dialogService)
        {
            _dialogService = dialogService;
        }

        #region 打开对话框

        /// <summary>
        /// 打开对话框 - 命令
        /// </summary>
        private DelegateCommand _showDialogCmd;

        /// <summary>
        /// 打开对话框 - 命令
        /// </summary>
        public DelegateCommand ShowDialogCmd =>
            _showDialogCmd ?? (_showDialogCmd = new DelegateCommand(ExecuteShowDialog));

        /// <summary>
        /// 执行 - 打开对话框
        /// </summary>    
        void ExecuteShowDialog()
        {
            _dialogService.ShowDialog(nameof(DialogShowView),new DialogParameters()
            {
                {"Title","这是一个Dialog的标题" }
            },callback =>
            {
                if(callback.Result == ButtonResult.OK)
                {
                    callback.Parameters.TryGetValue("Value", out string title);
                }
            });
        }

        #endregion 打开对话框
    }
}
